package com.template.domain.vo;

import com.template.domain.entity.SysMenu;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;

public class Sys {
    @Getter
    @Setter
    @Accessors(chain = true)
    public static class RouteMeta {
        private String title;
        private String icon;
        private Boolean newTab;
        private Integer type; // 类型(0:目录, 1:菜单, 2：按钮
        private Boolean isRoot; // 若类型为目录，并且此项为true，则组件为BasicLayout，否则只为RouterView
        private Boolean cache;
        private Boolean hide;
    }

    @Getter
    @Setter
    @Accessors(chain = true)
    public static class Route {
        private String name;
        private String path;
        private String component;
        private RouteMeta meta;
        private List<Route> children;

        public static Route menu2Route(SysMenu sysMenu) {
            Sys.RouteMeta routeMeta = new Sys.RouteMeta()
                    .setTitle(sysMenu.getName())
                    .setIcon(sysMenu.getIcon())
                    .setNewTab(sysMenu.getNewTab())
                    .setType(sysMenu.getType())
                    .setIsRoot(sysMenu.getParentId() == null)
                    .setCache(sysMenu.getCache())
                    .setHide(sysMenu.getHide());
            return new Sys.Route()
                    .setName(sysMenu.getRouteName())
                    .setPath(sysMenu.getRoutePath())
                    .setComponent(sysMenu.getComponent())
                    .setMeta(routeMeta);
        }
    }
}
